R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

mers <- read.csv('cases.csv')
mers$hospitalized[890] <-c('2015-02-20')
mers <- mers[-471,]
class(mers$onset)
## [1] "factor"
library(plotly)
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
mers$onset2 <- ymd(mers$onset)
mers$hospitalized2 <- ymd(mers$hospitalized)
## Warning: 5 failed to parse.
class(mers$onset2)
## [1] "Date"
day0 <-min(na.omit(mers$onset2))
mers$epi.day <- as.numeric(mers$onset2 - day0)

library(ggplot2)
ggplot(data = mers) + geom_bar(mapping=aes(x=epi.day)) + labs(x='epidemic day', y = 'case count', title='Global Count of MERS cases by date of symptom onset', caption='Data from: https://github/com/rambaut/MERS-Cases/blob/gh-pages/data/cases.csv')
## Warning: Removed 535 rows containing non-finite values (stat_count).

ggplotly(p=ggplot2::last_plot())
## Warning: Removed 535 rows containing non-finite values (stat_count).
ggplot(data = mers) +
  geom_bar(mapping = aes(epi.day, fill=country))+
  labs(x= 'epidemic day', y='case count', title="Global Count of MERS cases by date of symptom onset", caption="Data from: https://github.com/rambaut/MERS-Cases/blob/gh-pages/data/cases.csv")
## Warning: Removed 535 rows containing non-finite values (stat_count).
## Warning: position_stack requires non-overlapping x intervals

ggplotly(p=ggplot2::last_plot())
## Warning: Removed 535 rows containing non-finite values (stat_count).

## Warning: position_stack requires non-overlapping x intervals
mers$infectious.period <- mers$hospitalized2-mers$onset2 # calculate "raw" infectious period
class(mers$infectious.period) # these data are class 'difftime'
## [1] "difftime"
mers$infectious.period <- as.numeric(mers$infectious.period, units = 'days') #convert to days
ggplot(data=mers) + geom_histogram(aes(x=infectious.period)) + labs(x='infectious.period', y='frequency', title='Distribution of calculated MERS infectious peiord', caption='Data from: https://github.com/rambaut/MERS-Cases/blob/gh-pages/data/cases.csv')
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 727 rows containing non-finite values (stat_bin).

mers$infectious.period2 <- ifelse(mers$infectious.period<0,0,mers$infectious.period)
ggplot(data=mers) + geom_histogram(aes(x= infectious.period2)) + labs(x='Infectious period', y='Frequency', title ='Distribution of Calculated MERS infectious period (positive values only)', caption = 'Data from: https://github.com/rambaut/MERS???Cases/blob/gh???pages/data/cases.csv')
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 727 rows containing non-finite values (stat_bin).

ggplotly(p=ggplot2::last_plot())
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 727 rows containing non-finite values (stat_bin).
ggplot(data=mers)+ geom_density(mapping=aes(x=infectious.period2)) + labs(x='Infectious Period', y='Frequency', title='Probability density for MERS infectious period (positive values only)' , caption='Data from: https://github.com/rambaut/MERS???Cases/blob/gh???pages/data/cases.csv')
## Warning: Removed 727 rows containing non-finite values (stat_density).

ggplot(data=mers)+ geom_area(stat ='bin', mapping=aes(x=infectious.period2)) + labs(x='Infectious period', y='Freqeuncy', title='Area plot for MERS infectious period (positive values only)', caption='Data from: https://github.com/rambaut/MERS???Cases/blob/gh???pages/data/cases.csv')
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 727 rows containing non-finite values (stat_bin).

ggplot(data=mers)+ geom_dotplot(stat ='bin', mapping=aes(x=infectious.period2)) + labs(x='Infectious period', y='Freqeuncy', title='Area plot for MERS infectious period (positive values only)', caption='Data from: https://github.com/rambaut/MERS???Cases/blob/gh???pages/data/cases.csv')
## Warning: Ignoring unknown parameters: stat
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 727 rows containing non-finite values (stat_bindot).

ggplot(data=mers)+ geom_bar(stat ='bin', mapping=aes(x=infectious.period2)) + labs(x='Infectious period', y='Freqeuncy', title='Area plot for MERS infectious period (positive values only)', caption='Data from: https://github.com/rambaut/MERS???Cases/blob/gh???pages/data/cases.csv')
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 727 rows containing non-finite values (stat_bin).

ggplot(data=mers)+ geom_contour(stat ='bin', mapping=aes(x=infectious.period2)) + labs(x='Infectious period', y='Freqeuncy', title='Area plot for MERS infectious period (positive values only)', caption='Data from: https://github.com/rambaut/MERS???Cases/blob/gh???pages/data/cases.csv')
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 727 rows containing non-finite values (stat_bin).

ggplot(data=mers)+ geom_smooth(stat ='bin', mapping=aes(x=infectious.period2)) + labs(x='Infectious period', y='Freqeuncy', title='Area plot for MERS infectious period (positive values only)', caption='Data from: https://github.com/rambaut/MERS???Cases/blob/gh???pages/data/cases.csv')
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 727 rows containing non-finite values (stat_bin).

ggplot(data=mers)+ geom_smooth(method=loess, mapping=aes(x= epi.day, y=infectious.period2)) + labs(x='Infectious period', y='Freqeuncy', title='Area plot for MERS infectious period (positive values only)', caption='Data from: https://github.com/rambaut/MERS???Cases/blob/gh???pages/data/cases.csv')
## Warning: Removed 727 rows containing non-finite values (stat_smooth).

ggplot(data=mers, mapping=aes(x=epi.day, y=infectious.period2))+ geom_point(mapping = aes(color=country))+ facet_wrap(~ country)+ scale_y_continuous(limits = c(0, 50))+ labs(x='Epidemic Day', y= 'Infectious Period', title= 'MERS infectious period (positive value only) over time', caption= 'Data from: https://github.com/rambaut/MERS???Cases/blob/gh???pages/data/cases.csv')
## Warning: Removed 728 rows containing missing values (geom_point).

ggplotly(p=ggplot2::last_plot())
ggplot(data=mers, mapping=aes(x=epi.day, y=infectious.period2))+ geom_point(mapping = aes(color=city))+ facet_wrap(~ country)+ scale_y_continuous(limits = c(0, 50))+ labs(x='Epidemic Day', y= 'Infectious Period', title= 'MERS infectious period (positive value only) over time', caption= 'Data from: https://github.com/rambaut/MERS???Cases/blob/gh???pages/data/cases.csv')
## Warning: Removed 728 rows containing missing values (geom_point).

ggplotly(p=ggplot2::last_plot())
ggplot(data=subset(mers, gender %in% c('M', 'F') & country %in% c('KSA', 'Oman', 'Iran', 'Jordan', 'Qatar', 'South Korea', 'UAE'))) + geom_point(mapping=aes(x=epi.day, y = infectious.period2, color=country))+ facet_grid(gender ~ country) + scale_y_continuous(limits = c(0,50))+ labs(x='Epidemic day', y= 'Infectious period', title = 'MERS infectious period by gender and country', caption= 'Data from:https://github.com/rambaut/MERS???Cases/blob/gh???pages/data/cases.csv' )
## Warning: Removed 692 rows containing missing values (geom_point).

ggplotly(p=ggplot2::last_plot())

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.